<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <link rel="Shortcut Icon" href="../images/aecc.ico" type="image/x-icon" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <link rel="stylesheet" href="../StaticFiles/element-ui/element-ui.css">
  <link rel="stylesheet" href="../StaticFiles/nprogress/nprogress.min.css">
  <link rel="stylesheet" href="../styles/vue-page-common.css">
  <script src="../Scripts/vue.min.js"></script>
  <script src="../StaticFiles/element-ui/element-ui.js"></script>
  <script src="../Scripts/axios.min.js"></script>
  <script src="../StaticFiles/nprogress/nprogress.min.js"></script>
  <script src="../Scripts/dayjs.min.js"></script>
  <script src="../Scripts/axios.config.js"></script>
  <script src="../Scripts/crypto-js.min.js"></script>
  <script src="../Scripts/secret.js"></script>
  <title>热表转工排产报表</title>
  <style>
    .el-select .el-tag {
      display: inline-block;
    }

    .compute-info-zone .el-form-item {
      margin-bottom: 0px !important;
    }

    .el-date-editor--daterange.el-input,
    .el-date-editor--daterange.el-input__inner,
    .el-date-editor--timerange.el-input,
    .el-date-editor--timerange.el-input__inner {
      width: 300px;
    }
  </style>
</head>

<body>
  <div id="app" v-cloak v-on:keyup.enter="getData">
    <!-- 报表标题 -->
    <vue2-report-header :title="'热表转工排产报表'"></vue2-report-header>
    <div style="padding: 10px;">
      <!-- 汇总显示区域 -->
      <el-form class="compute-info-zone" :inline="true" :label-position="'left'">
        <el-form-item label="排产零件数:">
          <el-tag>{{computeData.productCount}}</el-tag>
        </el-form-item>

        <el-form-item label="排产工序数:">
          <el-tag>{{computeData.specCount}}</el-tag>
        </el-form-item>

        <el-form-item label="超期天数:">
          <el-tag type="danger">{{computeData.delaydaySum}}</el-tag>
        </el-form-item>

        <el-form-item label="超期工序数:">
          <el-tag type="warning">{{computeData.delaySpecCount}}</el-tag>
        </el-form-item>

        <el-form-item label="完工工序数:">
          <el-tag type="success">{{computeData.finishSpecCount}}</el-tag>
        </el-form-item>

        <el-form-item label="按时完工数:">
          <el-tag type="success">{{computeData.intimeFinishSpecCount}}</el-tag>
        </el-form-item>

        <el-form-item label="超期完成数:">
          <el-tag type="warning">{{computeData.delayFinishSpecCount}}</el-tag>
        </el-form-item>

        <el-form-item label="未完工序数:">
          <el-tag type="danger">{{computeData.notFinishSpecCount}}</el-tag>
        </el-form-item>

        <el-tooltip effect="dark" placement="top-start">
          <div slot="content">
            <p>完成率 = 完工工序数 ÷ 排产工序数</p>
          </div>
          <el-form-item label="完成率:">
            <el-tag type="success">{{computeData.finishRate}}%</el-tag>
          </el-form-item>
        </el-tooltip>

        <el-tooltip effect="dark" placement="top-start">
          <div slot="content">
            <p>按时完成率 = 按时完工数 ÷ 排产工序数</p>
          </div>
          <el-form-item label="按时完成率:">
            <el-tag type="success">{{computeData.intimeFinishRate}}%</el-tag>
          </el-form-item>
        </el-tooltip>

        <el-tooltip effect="dark" placement="top-start">
          <div slot="content">
            <p>超期完成率 = 超期完成数 ÷ 排产工序数</p>
          </div>
          <el-form-item label="超期完成率:">
            <el-tag type="warning">{{computeData.delayFinishRate}}%</el-tag>
          </el-form-item>
        </el-tooltip>

        <el-tooltip effect="dark" placement="top-start">
          <div slot="content">
            <p>未完成率 = 未完工序数 ÷ 排产工序数</p>
          </div>
          <el-form-item label="未完成率:">
            <el-tag type="danger">{{computeData.notFinishRate}}%</el-tag>
          </el-form-item>
        </el-tooltip>
        <el-form-item label="排产工序数（新）:">
          <el-tag>{{computeData.specCountNew}}</el-tag>
        </el-form-item>
        <el-form-item label="完工工序数（新）:">
          <el-tag type="success">{{computeData.finishSpecCountNew}}</el-tag>
        </el-form-item>
        <el-form-item label="超期完工数（新）:">
          <el-tag type="warning">{{computeData.delayFinishSpecCountNew}}</el-tag>
        </el-form-item>
        <el-form-item label="按时完工数（新）:">
          <el-tag type="success">{{computeData.intimeFinishSpecCountNew}}</el-tag>
        </el-form-item>
        <el-form-item>
          <template slot="label">
            <el-popover placement="top-start" title="" width="300" trigger="hover" content="">
              <i class="el-icon-info" slot="reference"></i>
              <p>和 <el-tag>完成率</el-tag> 相比，<el-tag>完成率（新）</el-tag> 增加查询主制分厂未及时发出的排产项。</p>
            </el-popover>
          </template>
          <el-form-item label="完成率（新）:">
            <el-tag type="success">{{computeData.finishRateNew}}%</el-tag>
          </el-form-item>
        </el-form-item>
        <el-form-item>
          <template slot="label">
            <el-popover placement="top-start" title="" width="300" trigger="hover" content="">
              <i class="el-icon-info" slot="reference"></i>
              <p>和 <el-tag>按时完成率</el-tag> 相比，<el-tag>按时完成率（新）</el-tag> 增加查询主制分厂未及时发出的排产项。</p>
            </el-popover>
          </template>
          <el-form-item label="按时完成率（新）:">
            <el-tag type="success" style="cursor:pointer;" @click="getIntimeFinishChartData">
              {{computeData.intimeFinishRateNew}}%</el-tag>
          </el-form-item>
        </el-form-item>
      </el-form>

      <!-- 查询条件区 -->
      <el-form class="query-zone" :inline="true" :model="queryInfo" :rules="rules" ref="queryInfoRef"
        :label-position="'left'">
        <el-form-item label="主制分厂:" prop="factoryname">
          <el-select v-model="queryInfo.fromfactoryid" placeholder="请选择分厂" clearable filterable>
            <el-option v-for="f in factoryList" :key="f.factoryid" :label="f.factoryname" :value="f.factoryid">
            </el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="承制分厂:">
          <el-select v-model="queryInfo.tofactoryid" placeholder="请选择主制分厂" @change="factorySelectChange">
            <el-option v-for="f in factoryList" :key="f.factoryid" :label="f.factoryname" :value="f.factoryid">
            </el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="承制工区:">
          <el-select v-model="queryInfo.toworkcenterid" placeholder="请选择" clearable filterable>
            <el-option v-for="w in workcenterList" :key="w.workcenterid" :label="w.workcentername"
              :value="w.workcenterid">
            </el-option>
          </el-select>
        </el-form-item>

        <el-form-item prop='productname' label="零件图号:">
          <el-autocomplete v-model.trim="queryInfo.productname" placeholder="请输入零件图号" :trigger-on-focus="false"
            style="width:240px;" :fetch-suggestions="searchProductAsync" :value-key="'productname'" :debounce="500">
          </el-autocomplete>
        </el-form-item>

        <el-form-item prop='containername' label="流水卡号:">
          <el-autocomplete v-model.trim="queryInfo.containername" placeholder="请输入流水卡号" :trigger-on-focus="false"
            style="width:240px;" :fetch-suggestions="searchContainerAsync" :value-key="'containername'" :debounce="500">
          </el-autocomplete>
        </el-form-item>

        <el-form-item prop="plannedfinishdate" label="计划完成时间:">
          <el-date-picker v-model="queryInfo.plannedfinishdate" type="daterange" range-separator="至"
            value-format="yyyy-MM-dd" start-placeholder="开始日期" end-placeholder="结束日期" :picker-options="pickerOptions">
          </el-date-picker>
        </el-form-item>

        <el-form-item prop="status" label="完成状态:">
          <el-select v-model="queryInfo.status" placeholder="请选择" style="width:100px;">
            <el-option :key="'待完成'" :value="'待完成'" :label="'待完成'"></el-option>
            <el-option :key="'待转入'" :value="'待转入'" :label="'待转入'"></el-option>
            <el-option :key="'已转入'" :value="'已转入'" :label="'已转入'"></el-option>
          </el-select>
        </el-form-item>

        <el-form-item>
          <el-button type="primary" icon="el-icon-search" size="mini" @click="handleSearch">查询</el-button>
          <el-button type="primary" icon="el-icon-download" size="mini" @click="getExportExcel">导出</el-button>
          <el-button type="primary" icon="el-icon-data-analysis" size="mini" @click="chartDialogVisiable=true">统计数据
          </el-button>
        </el-form-item>
      </el-form>

      <!-- 表格显示区 -->
      <el-table class="table-date-zone" v-loading="loading" v-loading.fullscreen.lock="loading"
        :element-loading-text="loadingText" element-loading-background="rgba(255,255,255,0.5)" :data="dataList" stripe
        border show-overflow-tooltip>
        <el-table-column type="index" width="40"></el-table-column>
        <el-table-column label="主制分厂" prop="fromfactory" width="90" show-overflow-tooltip></el-table-column>
        <el-table-column label="承制分厂" prop="tofactory" width="90" show-overflow-tooltip></el-table-column>
        <el-table-column label="承制工区" prop="toworkcentername" width="120" show-overflow-tooltip></el-table-column>
        <el-table-column label="流水卡号" prop="containername" show-overflow-tooltip width="200"></el-table-column>
        <el-table-column label="数量" prop="qty" width="60" fixed></el-table-column>
        <el-table-column label="排产工序" prop="workflowstepname" width="120" show-overflow-tooltip></el-table-column>
        <el-table-column label="当前工序" prop="currentworkflowstepname" width="120" show-overflow-tooltip>
        </el-table-column>
        <el-table-column label="计划完成时间" prop="plannedfinishdate" width="100">
          <template slot-scope="scope" v-if="scope.row.plannedfinishdate">
            <div v-if="scope.row.color === 'red'" style='background-color: red;'>
              {{scope.row.plannedfinishdate.split('T')[0]}}
            </div>
            <div v-else-if="scope.row.color === 'yellow'" style='background-color: yellow;'>
              {{scope.row.plannedfinishdate.split('T')[0]}}
            </div>
            <div v-else-if="scope.row.color === 'black'">
              {{scope.row.plannedfinishdate.split('T')[0]}}
            </div>
            <div v-else-if="scope.row.color === 'blue'" style='background-color: skyblue;'>
              {{scope.row.plannedfinishdate.split('T')[0]}}
            </div>
            <div v-else>
              {{scope.row.plannedfinishdate.split('T')[0]}}
            </div>
          </template>
        </el-table-column>
        <el-table-column label="计划发出时间" prop="plannedstartdate" width="100" :formatter="splitDate"></el-table-column>
        <el-table-column label="实际发出时间" prop="senddate" width="100" :formatter="splitDate"></el-table-column>
        <el-table-column label="接收时间" prop="toacceptdate" width="100" :formatter="splitDate"></el-table-column>
        <el-table-column label="接收人" prop="receiver" width="60"></el-table-column>
        <el-table-column label="实际完成时间" prop="completedate" width="100" :formatter="splitDate"></el-table-column>
        <el-table-column label="转入时间" prop="recivedate" width="100" :formatter="splitDate"></el-table-column>
        <el-table-column label="完成超期时间" prop="finishdelaydays" width="110">
          <template slot-scope="scope">
            <div v-if="scope.row.finishdelaydays > 0" style="color:red;font-weight:bold;">
              <i class="el-icon-warning"></i> {{scope.row.finishdelaydays}}天
            </div>
            <div v-else>
              {{scope.row.finishdelaydays}}
            </div>
          </template>
        </el-table-column>
        <el-table-column label="派工状态" prop="isdispatch" width="80">
          <template slot-scope="scope" v-if="scope.row.isdispatch">
            <el-tag :type="scope.row.isdispatch === '已派工'?'success':'danger'">{{scope.row.isdispatch}}</el-tag>
          </template>
        </el-table-column>
        <el-table-column label="零件图号" prop="productname" width="140" show-overflow-tooltip></el-table-column>
        <el-table-column label="零件名称" prop="productdescription" width="100" show-overflow-tooltip></el-table-column>
      </el-table>

      <!-- 分页组件 -->
      <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange"
        :current-page="queryInfo.currentPage" :page-sizes="[12,20,50]" :page-size="queryInfo.pageSize"
        layout="prev,pager,next,jumper,sizes,total" :total="total">
      </el-pagination>

      <!-- 回到顶部 -->
      <el-backtop></el-backtop>

      <el-dialog title="各分厂未及时发出项统计" :width="'85%'" :visible.sync="sendNotInTimeChartDialogVisiable"
        @opened="sendNotInTimeChartDialogOpend">
        <div id="sendNotInTimeChart" style="height: 600px;"></div>
      </el-dialog>

      <!-- 各分厂未及时发出项明细 -->
      <el-dialog :title="sendNotInTimeDetail.title" :width="'98%'" :top="'10px'"
        :visible.sync="sendNotInTimeDetail.dialogVisiable">
        <el-table v-loading="loading" v-loading.fullscreen.lock="loading" :element-loading-text="loadingText"
          element-loading-background="rgba(0,0,0,0.8)" :data="sendNotInTimeDetail.dataList" stripe border>
          <el-table-column type="index" width="40"></el-table-column>
          <el-table-column label="操作" width="100;">
            <template>
              <el-button type="primary" icon="el-icon-download" size="mini" @click="exportSendNotInTimeDetails">
                导出
              </el-button>
            </template>
          </el-table-column>
          <el-table-column label="主制分厂" prop="fromfactory" width="120" show-overflow-tooltip></el-table-column>
          <el-table-column label="承制分厂" prop="tofactory" width="120" show-overflow-tooltip></el-table-column>
          <el-table-column label="零件图号" prop="productname" width="140" show-overflow-tooltip></el-table-column>
          <el-table-column label="零件名称" prop="productdescription" width="100" show-overflow-tooltip></el-table-column>
          <el-table-column label="流水卡号" prop="containername" show-overflow-tooltip width="200"></el-table-column>
          <el-table-column label="数量" prop="qty" width="50"></el-table-column>
          <el-table-column label="排产工序" prop="workflowstepname" width="120px" show-overflow-tooltip></el-table-column>
          <el-table-column label="排产日期" prop="stepplancreatedate" width="100" :formatter="splitDate"></el-table-column>
          <el-table-column label="计划发出时间" prop="plannedstartdate" width="100" :formatter="splitDate"></el-table-column>
          <el-table-column label="实际发出时间" prop="senddate" width="100" :formatter="splitDate"></el-table-column>
          <el-table-column label="发出超期时间" prop="senddelaydays" width="100">
            <template slot-scope="scope">
              <div v-if="scope.row.senddelaydays > 0" style="color:red;font-weight:bold;">
                <i class="el-icon-warning"></i> {{scope.row.senddelaydays}}天
              </div>
              <div v-else>
                {{scope.row.senddelaydays}}
              </div>
            </template>
          </el-table-column>
          <el-table-column label="接收时间" prop="toacceptdate" width="100" :formatter="splitDate"></el-table-column>
          <el-table-column label="接收人" prop="receiver" width="60"></el-table-column>
          <el-table-column label="计划完成时间" prop="plannedfinishdate" width="100" :formatter="splitDate"></el-table-column>
          <el-table-column label="实际完成时间" prop="completedate" width="100" :formatter="splitDate"></el-table-column>
          <el-table-column label="转入时间" prop="recivedate" width="100" :formatter="splitDate"></el-table-column>
          <el-table-column label="当前工序" prop="currentworkflowstepname" width="120" show-overflow-tooltip>
          </el-table-column>
          <el-table-column label="完成超期时间" prop="finishdelaydays" width="100">
            <template slot-scope="scope">
              <div v-if="scope.row.finishdelaydays > 0" style="color:red;font-weight:bold;">
                <i class="el-icon-warning"></i> {{scope.row.finishdelaydays}}天
              </div>
              <div v-else>
                {{scope.row.finishdelaydays}}
              </div>
            </template>
          </el-table-column>
        </el-table>
        <el-pagination @current-change="handleSendNotInTimeDetailsCurrentChange"
          :current-page="sendNotInTimeDetail.queryInfo.currentPage"
          :page-sizes="[sendNotInTimeDetail.queryInfo.pageSize]" :page-size="sendNotInTimeDetail.queryInfo.pageSize"
          layout="prev,pager,next,jumper,sizes,total" :total="sendNotInTimeDetail.total">
        </el-pagination>
      </el-dialog>

      <!-- 转工完成情况 -->
      <el-dialog title="转工完成情况" :width="'98%'" :top="'40px'" :visible.sync="chartDialogVisiable"
        @opened="chartDialogOpened">
        <div id="chart" style="width:100%;height:700px;"></div>
      </el-dialog>

      <!-- 转工完成情况明细 -->
      <el-dialog :title="detail.title" :width="'100%'" :top="'10px'" :visible.sync="detail.dialogVisiable">
        <el-table v-loading="loading" v-loading.fullscreen.lock="loading" :element-loading-text="loadingText"
          element-loading-background="rgba(0,0,0,0.8)" :data="detail.dataList" stripe border>
          <el-table-column type="index" width="40"></el-table-column>
          <el-table-column label="主制分厂" prop="fromfactory" width="120" show-overflow-tooltip></el-table-column>
          <el-table-column label="承制分厂" prop="tofactory" width="120" show-overflow-tooltip></el-table-column>
          <el-table-column label="零件图号" prop="productname" width="140" show-overflow-tooltip></el-table-column>
          <el-table-column label="零件名称" prop="productdescription" width="100" show-overflow-tooltip></el-table-column>
          <el-table-column label="流水卡号" prop="containername" show-overflow-tooltip width="200"></el-table-column>
          <el-table-column label="数量" prop="qty" width="50px"></el-table-column>
          <el-table-column label="排产工序" prop="workflowstepname" width="120" show-overflow-tooltip></el-table-column>
          <el-table-column label="排产日期" prop="stepplancreatedate" width="100" :formatter="splitDate"></el-table-column>
          <el-table-column label="计划发出时间" prop="plannedstartdate" width="100" :formatter="splitDate"></el-table-column>
          <el-table-column label="实际发出时间" prop="senddate" width="100" :formatter="splitDate"></el-table-column>
          <el-table-column label="接收时间" prop="toacceptdate" width="100" :formatter="splitDate"></el-table-column>
          <el-table-column label="接收人" prop="receiver" width="60"></el-table-column>
          <el-table-column label="计划完成时间" prop="plannedfinishdate" width="100" :formatter="splitDate">
          </el-table-column>
          <el-table-column label="实际完成时间" prop="completedate" width="100" :formatter="splitDate"></el-table-column>
          <el-table-column label="转入时间" prop="recivedate" width="100" :formatter="splitDate"></el-table-column>
          <el-table-column label="当前工序" prop="currentworkflowstepname" width="120" show-overflow-tooltip>
          </el-table-column>
          <el-table-column label="完成超期时间" prop="finishdelaydays" width="100">
            <template slot-scope="scope">
              <div v-if="scope.row.finishdelaydays > 0" style="color:red;font-weight:bold;">
                <i class="el-icon-warning"></i> {{scope.row.finishdelaydays}}天
              </div>
              <div v-else>
                {{scope.row.finishdelaydays}}
              </div>
            </template>
          </el-table-column>
        </el-table>
        <!-- 分页 -->
        <el-pagination @current-change="handleDetailCurrentChange" :current-page="detail.queryInfo.currentPage"
          :page-sizes="[detail.queryInfo.pageSize]" :page-size="detail.queryInfo.pageSize"
          layout="prev,pager,next,jumper,sizes,total" :total="detail.total">
        </el-pagination>
      </el-dialog>
    </div>
  </div>
  <script src="../Scripts/echarts/echarts-5.4.0.min.js"></script>
  <script type="module">
    import { fetchSuggestion, exportExcelData, getParams } from '../Scripts/hooks/useCommonMethod.js'
    import { getWorkcenterList, getFactory } from '../Scripts/hooks/fetchAPI.js'
    import { barOption, colorList } from '../Scripts/hooks/chartConfig.js'
    import { pieOption } from '../Scripts/hooks/pieChartConfig.js'
    import { prevWeek, thisWeek, nextWeek, prevMonth, thisMonth, nextMonth } from '../Scripts/hooks/useDateShortCut.js'
    import { splitDate } from '../Scripts/hooks/format.js'
    import Vue2ReportHeader from '../Scripts/components/Vue2ReportHeader.js'
    const app = new Vue({
      el: '#app',
      components: { Vue2ReportHeader },
      data: {
        splitDate,
        loading: false,
        loadingText: '数据加载中...',
        total: 0,
        factoryList: [],
        workcenterList: [],
        queryInfo: {
          tofactoryid: '',//承制分厂
          toworkcenterid: '',//承制工区
          fromfactoryid: '',//发出分厂
          productname: '',//零件图号
          containername: '',//流水卡号
          plannedfinishdate: '',// 计划完成时间
          status: '', // 完成状态
          currentPage: 1,//当前页
          pageSize: 12//每页显示条数
        },
        dataList: [],
        computeData: {},
        // 表单验证
        rules: { plannedfinishdate: [{ required: true, message: '此必填项不能为空', trigger: 'change' }] },
        sendNotInTimeChartDialogVisiable: false, // 各分厂未及时发出项统计--对话框
        sendNotInTimeDetail: {
          dialogVisiable: false,
          queryInfo: { factoryname: '', currentPage: 1, pageSize: 13 },
          dataList: [], total: 0, title: ''
        },
        chartDialogVisiable: false,
        detail: {
          dialogVisiable: false,
          queryInfo: { fromfactory: '', title: '', currentPage: 1, pageSize: 14 },
          dataList: [], total: 0, title: ''
        },
        chartLoadingConfig: { text: '数据查询中...', effect: 'whirling', maskColor: 'transparent', textColor: '#000', color: '#66b1ff' },
        pickerOptions: { shortcuts: [prevWeek, thisWeek, nextWeek, prevMonth, thisMonth, nextMonth] }
      },
      methods: {
        // 查询件号
        searchProductAsync(value, callback) {
          fetchSuggestion({ actionName: 'getProductnameAsync', name: 'productname', value, callback })
        },
        // 查询批次号
        searchContainerAsync(value, callback) {
          fetchSuggestion({ actionName: 'getContainernameAsync', name: 'containername', value, callback })
        },
        async factorySelectChange(factoryid) {
          this.queryInfo.toworkcenterid = null;
          if (factoryid) { this.workcenterList = await getWorkcenterList({ factoryid }); }
        },
        // 查询数据
        async getData() {
          this.loading = true;
          this.loadingText = '数据加载中...';
          const { data: { data, meta, total } } = await axios.post('../handler/report/RBContainerShipPlanReport.ashx?action=getData', {
            type: 'getData',
            ...this.queryInfo
          })
          this.loading = false;
          if (meta.status === 500) { return this.$message.error(meta.msg); }
          this.dataList = data;
          this.total = total;
        },
        // 查询统计数据
        async getCompute() {
          const { data: { data, meta, total } } = await axios.post('../handler/report/RBContainerShipPlanReport.ashx?action=getCompute', {
            type: 'getCompute',
            ...this.queryInfo
          })
          this.loading = false;
          if (meta.status === 500) { return this.$message.error(meta.msg); }
          if (data && data.length > 0) { this.computeData = data[0]; }
        },
        // 查询按钮
        handleSearch() {
          this.$refs['queryInfoRef'].validate((valid) => {
            if (valid) {
              this.getData();
              this.getCompute();
            } else {
              this.$message.error('必填项不能为空');
            }
          })
        },
        //导出excel
        async getExportExcel() {
          if (!this.queryInfo.plannedfinishdate) {
            return this.$message.error('必填项不能为空');
          }
          const config = {
            url: '../handler/report/RBContainerShipPlanReport.ashx?action=exportExcel',
            data: { type: 'exportExcel', ...this.queryInfo }
          }
          exportExcelData(config, this);
        },
        // 查询按时完成率A数据
        getIntimeFinishChartData() {
          this.sendNotInTimeChartDialogVisiable = true;
        },
        // 各分厂未及时发出统计对话框被打开时
        async sendNotInTimeChartDialogOpend() {
          echarts.dispose(document.getElementById("sendNotInTimeChart"));
          let chart = echarts.init(document.getElementById('sendNotInTimeChart'));
          chart.showLoading(this.chartLoadingConfig);

          const { data: { data, meta } } = await axios.post('../handler/report/RBContainerShipPlanReport.ashx?action=getSendNotInTimeChartData', {
            type: 'getSendNotInTimeChartData',
            ...this.queryInfo
          })
          chart.hideLoading();
          if (meta.status === 500) { return this.$message.error(meta.msg); }
          if (data.length === 0) { return; }

          echarts.dispose(document.getElementById("sendNotInTimeChart"));
          chart = echarts.init(document.getElementById('sendNotInTimeChart'));

          let pieData = [];
          for (const item of data) {
            pieData.push({ value: item.qty, name: item.fromfactory })
          }

          let option = pieOption({ title: '各分厂未及时发出项统计', data: pieData });
          chart.setOption(option);
          chart.on('click', (params) => {
            this.sendNotInTimeDetail.queryInfo.currentPage = 1;
            this.sendNotInTimeDetail.queryInfo.factoryname = params.name;
            this.sendNotInTimeDetail.title = "【" + params.name + "】未及时发出明细";
            this.sendNotInTimeDetail.dialogVisiable = true;
            this.getSendNotInTimeDetails();
          })
        },
        // 各分厂未及时发出--明细
        async getSendNotInTimeDetails() {
          this.loading = true;
          this.loadingText = '数据加载中...';
          const { data: { data, meta, total } } = await axios.post('../handler/report/RBContainerShipPlanReport.ashx?action=getSendNotInTimeDetails', {
            type: 'getSendNotInTimeDetails',
            ...this.queryInfo,
            ...this.sendNotInTimeDetail.queryInfo
          })
          this.loading = false;
          if (meta.status === 500) { return this.$message.error(meta.msg); }
          this.sendNotInTimeDetail.dataList = data;
          this.sendNotInTimeDetail.total = total;
        },
        // 各分厂未及时发出--导出
        async exportSendNotInTimeDetails() {
          const config = {
            url: '../handler/report/RBContainerShipPlanReport.ashx?action=exportSendNotInTimeDetails',
            data: {
              type: 'exportSendNotInTimeDetails',
              ...this.queryInfo,
              ...this.sendNotInTimeDetail.queryInfo
            }
          }
          exportExcelData(config, this);
        },
        handleCurrentChange(newPage) {
          this.queryInfo.currentPage = newPage;
          this.getData();
        },
        handleSendNotInTimeDetailsCurrentChange(newPage) {
          this.sendNotInTimeDetail.queryInfo.currentPage = newPage
          this.getSendNotInTimeDetails()
        },
        handleSizeChange(newSize) {
          this.queryInfo.pageSize = newSize;
          this.getData();
        },
        async chartDialogOpened() {
          echarts.dispose(document.getElementById("chart"));
          let chart = echarts.init(document.getElementById('chart'));
          chart.showLoading(this.chartLoadingConfig);
          const { data: { data, meta } } = await axios.post('../handler/report/RBContainerShipPlanReport.ashx?action=getChart', {
            type: 'getChart',
            ...this.queryInfo
          })
          chart.hideLoading();
          if (meta.status === 500) { return this.$message.error(meta.msg); }
          if (data.length === 0) { return; }

          echarts.dispose(document.getElementById("chart"));
          chart = echarts.init(document.getElementById('chart'));

          let arrFactoryname = [], arrSpecCount = [], arrIntimeFinishSpecCount = [], arrDelayFinishSpecCount = [], arrIntimeFinishRate = [];
          for (const i of data) {
            arrFactoryname.push(i.fromfactory);
            arrSpecCount.push(i.speccount);
            arrIntimeFinishSpecCount.push(i.intimefinishspeccount);
            arrDelayFinishSpecCount.push(i.delayfinishspeccount);
            arrIntimeFinishRate.push(i.intimefinishrate);
          }

          let option = barOption({ themeColor: 'dark' });
          option.legend.data = ['计划完成项', '按时完工数', '超期完工数', '按时完成率'];//设置图例文字
          option.xAxis.data = arrFactoryname;

          option.series[0] = _.merge(option.series[0], {
            name: '计划完成项',
            data: arrSpecCount,
            label: { color: colorList.blue.color },
            itemStyle: { color: { colorStops: colorList.blue.colorStops } }
          });

          option.series[1] = _.merge(_.cloneDeep(option.series[0]), {
            name: '按时完工数',
            data: arrIntimeFinishSpecCount,
            label: { color: colorList.green.color },
            itemStyle: { color: { colorStops: colorList.green.colorStops } }
          });

          option.series[2] = _.merge(_.cloneDeep(option.series[0]), {
            name: '超期完工数',
            data: arrDelayFinishSpecCount,
            label: { color: colorList.red.color },
            itemStyle: { color: { colorStops: colorList.red.colorStops } }
          });

          option.series[3] = _.merge(_.cloneDeep(option.series[0]), {
            name: '按时完成率',
            data: arrIntimeFinishRate,
            type: 'line',
            symbolSize: 8,
            yAxisIndex: 1,
            label: { color: colorList.black.color, formatter: '{c}%' },
            lineStyle: { width: 3, color: colorList.black.color },
            itemStyle: { color: { colorStops: colorList.black.colorStops } }
          });

          chart.setOption(option);
          chart.on('click', (params) => {
            if (params.seriesName === '按时完成率') { return; }
            if (params.value == 0) { return; }
            this.detail.queryInfo.currentPage = 1;
            this.detail.title = `${params.name} 【${params.seriesName}】明细`;
            this.detail.dialogVisiable = true;
            this.detail.queryInfo.fromfactory = params.name;
            this.detail.queryInfo.seriesName = params.seriesName;
            this.detail.queryInfo.title = `${params.name} 【${params.seriesName}】明细`;
            this.getChartDetail();
          })
        },
        async getChartDetail() {
          this.loading = true;
          this.loadingText = '数据加载中...';
          const { data: { data, meta, total } } = await axios.post('../handler/report/RBContainerShipPlanReport.ashx?action=getChartDetail', {
            type: 'getChartDetail',
            ...this.queryInfo,
            ...this.detail.queryInfo
          })
          this.loading = false;
          if (meta.status === 500) { return this.$message.error(meta.msg); }
          this.detail.dataList = data;
          this.detail.total = total;
        },
        handleDetailCurrentChange(newPage) {
          this.detail.queryInfo.currentPage = newPage;
          this.getChartDetail();
        }
      },
      async mounted() {
        this.factoryList = await getFactory();
        const factoryid = Decrypt(getParams('factoryid'));
        this.queryInfo.tofactoryid = factoryid;
        this.workcenterList = await getWorkcenterList({ factoryid });
        const lastSaturday = dayjs().day(0).subtract(1, 'day').format('YYYY-MM-DD');
        const friday = dayjs().startOf('week').add(5, 'day').format('YYYY-MM-DD');
        this.queryInfo.plannedfinishdate = [lastSaturday, friday];
      },
      watch: {
        queryInfo: { handler() { this.queryInfo.currentPage = 1 }, deep: true }
      }
    })
  </script>
</body>

</html>